home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / share / tix4.1 / demos / MkChoose.tcl next >
Encoding:
Text File  |  1998-12-04  |  8.8 KB  |  280 lines

  1. # MkChoose.tcl --
  2. #
  3. #    This file implements the "Choosers" page in the widget demo
  4. #
  5. #    This file has not been properly documented. It is NOT intended
  6. #    to be used as an introductory demo program about Tix
  7. #    programming. For such demos, please see the files in the
  8. #    demos/samples directory or go to the "Samples" page in the
  9. #    "widget demo"
  10. #
  11. #
  12. # Copyright (c) 1996, Expert Interface Technologies
  13. #
  14. # See the file "license.terms" for information on usage and redistribution
  15. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  16. #
  17.  
  18.  
  19.  
  20. proc MkChoosers {nb page} {
  21.     set w [$nb subwidget $page]
  22.  
  23.     set name [tixOptionName $w]
  24.     option add *$name*TixLabelFrame*label.padX 4
  25.  
  26.     tixLabelFrame $w.til -label "Chooser Widgets"
  27.     tixLabelFrame $w.cbx -label "tixComboBox"
  28.     tixLabelFrame $w.ctl -label "tixControl"
  29.     tixLabelFrame $w.sel -label "tixSelect"
  30.     tixLabelFrame $w.opt -label "tixOptionMenu"
  31.     tixLabelFrame $w.fil -label "tixFileEntry"
  32.     tixLabelFrame $w.fbx -label "tixFileSelectBox"
  33.     tixLabelFrame $w.tbr -label "Tool Bar"
  34.  
  35.     MkTitle   [$w.til subwidget frame]
  36.     MkCombo   [$w.cbx subwidget frame]
  37.     MkControl [$w.ctl subwidget frame]
  38.     MkSelect  [$w.sel subwidget frame]
  39.     MkOptMenu [$w.opt subwidget frame]
  40.     MkFileBox [$w.fbx subwidget frame]
  41.     MkFileEnt [$w.fil subwidget frame]
  42.     MkToolBar [$w.tbr subwidget frame]
  43.     
  44.     #
  45.     # First column: comBox and selector
  46.     tixForm $w.cbx -top 0 -left 0 -right %33
  47.     tixForm $w.sel -left 0 -right &$w.cbx -top $w.cbx
  48.     tixForm $w.opt -left 0 -right &$w.cbx -top $w.sel -bottom -1
  49.  
  50.     #
  51.     # Second column: title .. etc
  52.     tixForm $w.til -left $w.cbx -right %66 -top 0
  53.     tixForm $w.ctl -left $w.cbx -right &$w.til -top $w.til
  54.     tixForm $w.fil -left $w.cbx -right &$w.til -top $w.ctl
  55.     tixForm $w.tbr -left $w.cbx -right &$w.til -top $w.fil -bottom -1
  56.  
  57.     #
  58.     # Third column: file selection
  59.     tixForm $w.fbx -left %66  -right -1 -top 0
  60. }
  61.  
  62. #----------------------------------------------------------------------
  63. #     ComboBox
  64. #----------------------------------------------------------------------
  65. proc MkCombo {w} {
  66.     set name [tixOptionName $w]
  67.     option add *$name*TixComboBox*label.width 10
  68.     option add *$name*TixComboBox*label.anchor e
  69.     option add *$name*TixComboBox*entry.width 14
  70.     
  71.     tixComboBox $w.static   -label "Static" \
  72.     -editable false 
  73.     tixComboBox $w.editable -label "Editable" \
  74.     -editable true
  75.     tixComboBox $w.history  -label "History" \
  76.     -editable true -history true -anchor e
  77.  
  78.     $w.static insert end January
  79.     $w.static insert end February
  80.     $w.static insert end March
  81.     $w.static insert end April
  82.     $w.static insert end May
  83.     $w.static insert end June
  84.     $w.static insert end July
  85.     $w.static insert end August
  86.     $w.static insert end September
  87.     $w.static insert end October
  88.     $w.static insert end November
  89.     $w.static insert end December
  90.  
  91.     $w.editable insert end "America"
  92.     $w.editable insert end "Britain"
  93.     $w.editable insert end "China"
  94.     $w.editable insert end "Denmark"
  95.     $w.editable insert end "Egypt"
  96.  
  97.     $w.history insert end "/usr/bin/mail"
  98.     $w.history insert end "/etc/profile"
  99.     $w.history insert end "/home/d/doe/Mail/letter"
  100.  
  101.     pack $w.static $w.editable $w.history -side top -padx 5 -pady 3
  102. }
  103.  
  104. #----------------------------------------------------------------------
  105. #             The Control widgets
  106. #----------------------------------------------------------------------
  107. set states {Alabama "New York" Pennsylvania Washington}
  108.  
  109. proc stCmd {w by value} {
  110.     global states
  111.  
  112.     set index [lsearch $states $value]
  113.     set len   [llength $states]
  114.     set index [expr $index + $by]
  115.            
  116.     if {$index < 0} {
  117.     set index [expr $len -1]
  118.     }
  119.     if {$index >= $len} {
  120.     set index 0
  121.     }
  122.  
  123.     return [lindex $states $index]
  124. }
  125.  
  126. proc stValidate {w value} {
  127.     global states
  128.  
  129.     if {[lsearch $states $value] == -1} {
  130.     return [lindex $states 0]
  131.     } else {
  132.     return $value
  133.     }
  134. }
  135.  
  136. proc MkControl {w} {
  137.     set name [tixOptionName $w]
  138.     option add *$name*TixControl*label.width 10
  139.     option add *$name*TixControl*label.anchor e
  140.     option add *$name*TixControl*entry.width 13
  141.  
  142.  
  143.     tixControl $w.simple -label Numbers
  144.  
  145.     tixControl $w.spintext -label States \
  146.     -incrcmd "stCmd $w.spintext 1" \
  147.     -decrcmd "stCmd $w.spintext -1" \
  148.     -validatecmd "stValidate .d" \
  149.     -value "Alabama"
  150.  
  151.     pack $w.simple $w.spintext -side top -padx 5 -pady 3
  152. }
  153.  
  154. #----------------------------------------------------------------------
  155. #             The Select Widgets
  156. #----------------------------------------------------------------------
  157. proc MkSelect {w} {
  158.     set name [tixOptionName $w]
  159.     option add *$name*TixSelect*label.anchor c
  160.     option add *$name*TixSelect*orientation vertical
  161.     option add *$name*TixSelect*labelSide top
  162.  
  163.     tixSelect $w.sel1 -label "Mere Mortals" -allowzero true -radio true
  164.     tixSelect $w.sel2 -label "Geeks" -allowzero true -radio false
  165.  
  166.     $w.sel1 add eat   -text Eat
  167.     $w.sel1 add work  -text Work
  168.     $w.sel1 add play  -text Play
  169.     $w.sel1 add party -text Party
  170.     $w.sel1 add sleep -text Sleep
  171.  
  172.     $w.sel2 add eat   -text Eat
  173.     $w.sel2 add prog1 -text Program
  174.     $w.sel2 add prog2 -text Program
  175.     $w.sel2 add prog3 -text Program
  176.     $w.sel2 add sleep -text Sleep
  177.  
  178.     pack $w.sel1 $w.sel2 -side left -padx 5 -pady 3 -fill x
  179. }
  180. #----------------------------------------------------------------------
  181. #             The OptMenu Widget
  182. #----------------------------------------------------------------------
  183. proc MkOptMenu {w} {
  184.     set name [tixOptionName $w]
  185.  
  186.     option add *$name*TixOptionMenu*label.anchor e
  187.  
  188.     tixOptionMenu $w.menu -label "File Format : " \
  189.     -options {
  190.         menubutton.width 15
  191.     }
  192.  
  193.     $w.menu add command text   -label "Plain Text"      
  194.     $w.menu add command post   -label "PostScript"      
  195.     $w.menu add command format -label "Formatted Text"  
  196.     $w.menu add command html   -label "HTML"            
  197.     $w.menu add separator sep
  198.     $w.menu add command tex    -label "LaTeX"           
  199.     $w.menu add command rtf    -label "Rich Text Format"
  200.  
  201.     pack $w.menu -padx 5 -pady 3 -fill x
  202. }
  203.  
  204. #----------------------------------------------------------------------
  205. #     FileEntry
  206. #----------------------------------------------------------------------
  207. proc MkFileEnt {w} {
  208.     set name [tixOptionName $w]
  209.  
  210.     message $w.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
  211.     -relief flat -width 240 -anchor n\
  212.     -text {Press the "open file" icon button and a\
  213. TixFileSelectDialog will popup.}
  214.  
  215.     tixFileEntry $w.ent -label "Select a file : "
  216.  
  217.     pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  218.     pack $w.ent -side top -fill x -padx 3 -pady 3
  219. }
  220.  
  221. proc MkFileBox {w} {
  222.     set name [tixOptionName $w]
  223.  
  224.     message $w.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
  225.     -relief flat -width 240 -anchor n\
  226.     -text {The TixFileSelectBox is Motif-style file selection\
  227. box with various enhancements. For example, you can adjust the\
  228. size of the two listboxes and your past selections are recorded.}
  229.  
  230.     tixFileSelectBox $w.box
  231.  
  232.     pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  233.     pack $w.box -side top -fill x -padx 3 -pady 3
  234. }
  235.  
  236. #----------------------------------------------------------------------
  237. #     Tool Bar
  238. #----------------------------------------------------------------------
  239. proc MkToolBar {w} {
  240.     set name [tixOptionName $w]
  241.  
  242.     option add $name*TixSelect*frame.borderWidth 1
  243.     message $w.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
  244.     -relief flat -width 240 -anchor n\
  245.     -text {The Select widget is also good for arranging buttons\
  246. in a tool bar.}
  247.  
  248.     frame $w.bar -bd 2 -relief raised
  249.     tixSelect $w.font -allowzero true  -radio false -label {}
  250.     tixSelect $w.para -allowzero false -radio true -label {}
  251.  
  252.     $w.font add bold      -bitmap [tix getbitmap bold]
  253.     $w.font add italic    -bitmap [tix getbitmap italic]
  254.     $w.font add underline -bitmap [tix getbitmap underlin]
  255.     $w.font add capital   -bitmap [tix getbitmap capital]
  256.  
  257.     $w.para add left    -bitmap [tix getbitmap leftj]
  258.     $w.para add right   -bitmap [tix getbitmap rightj]
  259.     $w.para add center  -bitmap [tix getbitmap centerj]
  260.     $w.para add justify -bitmap [tix getbitmap justify]
  261.  
  262.     pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  263.     pack $w.bar -side top -fill x -padx 3 -pady 3
  264.     pack $w.para $w.font -in $w.bar -side left -padx 4 -pady 3
  265. }
  266. #----------------------------------------------------------------------
  267. #     Title
  268. #----------------------------------------------------------------------
  269. proc MkTitle {w} {
  270.     set name [tixOptionName $w]
  271.  
  272.     option add $name*TixSelect*frame.borderWidth 1
  273.     message $w.msg -font -*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*\
  274.     -relief flat -width 240 -anchor n\
  275.     -text {There are many types of "choose" widgets that allow\
  276. the user to input different type of information.}
  277.  
  278.     pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  279. }
  280.